package com.longteng.diamond.controller;


import com.longteng.diamond.domain.User;
import com.longteng.diamond.po.RequestResult;
import com.longteng.diamond.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Collection;

/**
 * Created by Administrator
 * DATE : 2018/7/4
 * TIME : 22:53
 * PROJECT : java-lesson
 * PACKAGE : com.longteng.lesson
 *
 * @author <a href="mailto:taki@qq.com">Administrator</a>
 */
@Slf4j
@RestController
@RequestMapping("/userController")
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping("/setProject")
    public void serProject(int projectId, HttpSession session){
      User user= (User) session.getAttribute("user");
      user.setLastProjectId(projectId);
      session.setAttribute("user",user);
      //更新数据库
    }

    @RequestMapping("getAllUser")
    public RequestResult getAllUser(){
        RequestResult requestResult =new RequestResult();
        try {
            Collection<User> userList=userService.getAllUser();
            requestResult.setSuccess(true);
            requestResult.setObj(userList);
        }catch (Exception e){
            log.error("获取用户异常",e);
            requestResult.setSuccess(false);
            requestResult.setMsg("获取用户异常");
        }
        return requestResult;
    }
}
